// https://www.luogu.com.cn/problem/P1776
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
#define MAX_SIZE 40005
#define MAXN 105

int n, m;
int p[MAX_SIZE], v[MAX_SIZE];
int f[2][MAX_SIZE];

int tsiz, tp[MAXN], tv[MAXN], tc[MAXN];

void init() {
    rf(i, tsiz) {
        for (int base = 1; tc[i] > 0; base *= 2) {
            base = min(base, tc[i]);
            p[++n] = base * tp[i], v[n] = base * tv[i], tc[i] -= base;
        }
    }
}

int main() {
    scanf("%d%d", &tsiz, &m);
    rf(i, tsiz) scanf("%d%d%d", tp + i, tv + i, tc + i);
    init();

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            f[i & 1][j] = f[i - 1 & 1][j];
            if (j >= v[i]) f[i & 1][j] = max(f[i & 1][j], f[i - 1 & 1][j - v[i]] + p[i]);
        }
    }
    printf("%d", f[n & 1][m]);
}
